<?php
$hosts = array("tieba.baidu.com", "baike.baidu.com", "map.baidu.com");
$timeout = 15;
$status = array();
foreach ($hosts as $host) {
$errno = 0;
$errstr = "";
$s = fsockopen($host, 80, $errno, $errstr, $timeout);
if ($s) {
  $status[$host] = "Connectedn";
  fwrite($s, "HEAD / HTTP/1.0rnHost: $hostrnrn");
  do {
   $data = fread($s, 8192);
   if (strlen($data) == 0) {
   break;
   }
   $status[$host] .= $data;
  } while (true);
  fclose($s);
} else {
  $status[$host] = "Connection failed: $errno $errstrn";
}
}
print_r($status);